from rest_framework import request
from rest_framework.response import Response
from rest_framework.views import APIView

from bigevents_admin.serializers.register import RegisterSerializer


class RegisterView(APIView):
    """用户注册"""
    def post(self, request):
        # 1.接收前端的注册信息
        data = request.data
        # 2.验证用户名和密码
        serializer = RegisterSerializer(data=data)

        serializer.is_valid()
        try:
            serializer.save()
        except Exception as e:
            return Response({"status": 1, "message": "注册失败！"})
        # 3.返回结果
        return Response({"status": 0, "message": "注册成功！"})
